// a set of functions to help us draw and clear drawings from the canvas

function drawGrid() {
	
	context.strokeStyle = "red";
	
	context.moveTo(0, 0);
	context.lineTo(0, canvas.height);
	context.stroke();
	
	context.moveTo(30, 0);
	context.lineTo(canvas.width, 0);
	context.stroke();
	
	context.moveTo(canvas.width, 0);
	context.lineTo(canvas.width, canvas.height - (cellDimentions * 2));
	context.stroke();
	
	context.moveTo(canvas.width, canvas.height - cellDimentions);
	context.lineTo(canvas.width, canvas.height);
	context.stroke();
	
	context.moveTo(canvas.width, canvas.height);
	context.lineTo(0, canvas.height);
	context.stroke();
	
}

function drawStewie() {
	if (up) {
		stewieUp = new Image();
		stewieUp.src="images/little-stewie-up.png";	
		stewieUp.onload = function() {		
			context.drawImage(stewieUp,currentStewieX,currentStewieY,stewieWidth,stewieHeight);
		};
		return;
	}
	if (down) {
		stewieDown=new Image();
		stewieDown.src="images/little-stewie-down.png";
		stewieDown.onload = function() {		
			context.drawImage(stewieDown,currentStewieX,currentStewieY,stewieWidth,stewieHeight);
		};
		return;
	}
	stewie = new Image();
	stewie.src="images/little-stewie.png";	
	stewie.onload = function() {		
		context.drawImage(stewie,currentStewieX,currentStewieY,stewieWidth,stewieHeight);
	};
}

function drawLois() {
	var img=new Image();
	img.src="images/lois-header.png";
	img.onload = function() {		
		context.drawImage(img,2,2,26,26);
	};
}

function drawSquareOnCanvas(x,y) {
	context.fillStyle="#FF0000";
	context.fillRect(x,y,cellDimentions,cellDimentions);
}

function drawMaze() {
	
	for (var i = 0 ; i < numberOfRows ; i++) {
		for (var j = 0 ; j < (numberOfColumns - 1) ; j++) {
			if (horiz[i][j] !=  1) {
				drawVerticalLine(cellDimentions * (j + 1), cellDimentions * i);
			}
			
		}
	}
	
	for (var i = 0 ; i < numberOfRows ; i++) {
		for (var j = 0 ; j < (numberOfColumns) ; j++) {
			if (verti[i][j] !=  1) {
				drawHorizontalLine(cellDimentions * j, cellDimentions * (i + 1));
			}
			
		}
	}
	
	
}

function drawVerticalLine(x,y) {
	context.strokeStyle = "black";
	context.moveTo(x, y);
	context.lineTo(x, y + cellDimentions);
	context.stroke();
}

function drawHorizontalLine(x,y) {
	
	context.strokeStyle = "black";
	context.moveTo(x, y);
	context.lineTo(x + cellDimentions, y);
	context.stroke();
}

//erases the a cell from the canvas
function clearStewie() { 
	context.clearRect(currentStewieX,currentStewieY,stewieWidth,stewieHeight);
}

function drawHorizontalShot() {
	context.fillStyle = "red";
	context.fillRect(currentShotX ,currentShotY , horizontalShotWidth,horizontalShotHeight);
}

function clearHorizontalShot() { 
	context.clearRect(currentShotX,currentShotY,horizontalShotWidth,horizontalShotHeight);
}

function drawVerticalShot() {
	context.fillStyle = "red";
	context.fillRect(currentShotX ,currentShotY , verticalShotWidth,verticalShotHeight);
}

function clearVerticalShot() { 
	context.clearRect(currentShotX,currentShotY,verticalShotWidth,verticalShotHeight);
}

function eraseVerticalWall(x, y) {
	context.clearRect(x * cellDimentions - 1,y * cellDimentions + 1,2,cellDimentions - 2);
}

function eraseHorizontalWall(x,y) {
	context.clearRect(x * cellDimentions + 1 ,y * cellDimentions - 1,cellDimentions - 1,2);
}

function clearCanvas() {
	context.clearRect(0,0,canvas.width,canvas.height);
	context.beginPath();
}